package java_常用api;

public class API_2_equals {
    int age;
    String name;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        API_2_equals that = (API_2_equals) o;

        if (age != that.age) return false;
        return name != null ? name.equals(that.name) : that.name == null;
    }

//    @Override
//    public int hashCode() {
//        int result = age;
//        result = 31 * result + (name != null ? name.hashCode() : 0);
//        return result;
//    }

    API_2_equals(int i , String n){
        age = i ;
        name = n;


    }

    public static void main(String[] args) {
        API_2_equals dx1 = new API_2_equals(18,"赤城");
        API_2_equals dx2 = new API_2_equals(18, "赤城");

        System.out.println(dx1 == dx2);
        System.out.println(dx1.equals(dx2));
    }
}
